package com.example.purplestarcb.shoujizhushou;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by PurpleStarCB on 2015/3/20.
 */
public class AccelerateFragment extends Fragment{
    private GridView listHome;
    private Adapter adapter;
    protected static final String TAG="AccelerateFragment";
    //这里是文字信息
    private static String[] listNames={
            "清理加速","话费流量","骚扰拦截",
            "手机通讯","支付保镖","手机杀毒"

    };
    //这里是图片文件
    private  int[] ids={
            R.drawable.exam_frequently_used_tools_icon_clean,
            R.drawable.exam_frequently_used_tools_icon_net_traffic,
            R.drawable.exam_frequently_used_tools_icon_block_anoy,
            R.drawable.exam_frequently_used_tools_icon_txl,
            R.drawable.exam_frequently_used_tools_icon_guardpay,
            R.drawable.exam_frequently_used_tools_icon_malware
    };

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.accelerate_layout, container, false);

        GridView gridView =(GridView)view.findViewById(R.id.accelerata_listHome);
        //注意这里
        adapter=new MyAdapt(view.getContext());
        gridView.setAdapter((android.widget.ListAdapter) adapter);
        //设置GradView点击事件
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            /**
             *
             * @param parent 传递gradView
             * @param view 传递view
             * @param position 传递位置
             * @param id 传递ID
             */
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    switch (position){
                        //清理加速
                        case 0:
                            break;
                        //话费流量
                        case 1:
                            SendSMS sms=new SendSMS();
                            sms.sendSMS("10001","1081");
                            break;
                        //骚扰拦截
                        case 2:
                            break;
                        //手机通讯
                        case 3:
                            break;
                        //支付保镖
                        case 4:
                            break;
                        //手机杀毒
                        case 5:
                            break;
                    }
            }
        });
        return view;
    }


    private class MyAdapt extends BaseAdapter {

        public MyAdapt(Context context) {

        }

        @Override
        public int getCount() {
            return listNames.length;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            //注意这里是getActivity 不是AccelerateFragment.this
            View view=View.inflate(getActivity(),R.layout.list_item,null);
            ImageView iv_item= (ImageView) view.findViewById(R.id.iv_item);
            TextView tv_item= (TextView) view.findViewById(R.id.tv_item);

            tv_item.setText(listNames[position]);
            iv_item.setImageResource(ids[position]);
            return view;
        }
    }


}
